@file:Suppress("unused")

package com.example.demo.model

import xyz.erupt.annotation.*
import xyz.erupt.annotation.sub_erupt.*
import xyz.erupt.annotation.sub_field.*
import xyz.erupt.annotation.sub_field.sub_edit.*
import xyz.erupt.jpa.model.*
import javax.persistence.*

@Entity
@Table(name = "demo_tree")
@Erupt(
    name = "树示例",
    orderBy = "TreeView.sort",
    tree = Tree(pid = "parent.id"),
)
class TreeView : BaseModel() {

    @EruptField(
        views = [View(title = "名称")],
        edit = Edit(title = "名称", notNull = true),
    )
    var name: String = ""

    @EruptField(
        views = [View(title = "显示顺序")],
        edit = Edit(title = "显示顺序"),
    )
    var sort: Int? = null

    @ManyToOne
    @EruptField(
        edit = Edit(
            title = "上级树节点",
            type = EditType.REFERENCE_TREE,
            referenceTreeType = ReferenceTreeType(pid = "parent.id"),
        ),
    )
    var parent: TreeView? = null //这里要设置成可空类型，因为根节点的parent必须为null

}